﻿namespace HCRS.Implementation
{
    using HCRS.BusinessEntities;
    using HCRS.DBACL;
    using System;
    using System.Data;

    public class FitEngine
    {
        /// <summary>
        /// 获取散客网站预订引擎
        /// </summary>
        /// <param name="fit">散客网站预订引擎</param>
        /// <returns>散客网站预订引擎</returns>
        public CRMFitEngine GetCRMFitEngine(CRMFitEngine fit)
        {
            if ((fit.id == 0) && (fit.userid == 0))
            {
                return null;
            }
            DataAccessLayer layer = new DataAccessLayer();
            string sQL = "";
            if (fit.id != 0)
            {
                sQL = "select a.*,c.IATA,c.Corp_id from CRM_fit_engine_domain a inner join [user] b on a.userid=b.userid and (b.lockuser=0 and  b.congeal<1) and a.id=" + fit.id + " inner join  Corp c on c.Corp_id=b.parentid";
            }
            if (fit.userid != 0)
            {
                sQL = string.Concat(new object[] { "select a.*,c.IATA,c.Corp_id from CRM_fit_engine_domain a inner join [user] b on  a.userid=b.userid and (b.lockuser=0 and  b.congeal<1) and a.userid=", fit.userid, " and  a.languagetype=", fit.languagetype, " inner join  Corp c on c.Corp_id=b.parentid" });
            }
            DataRow row = layer.RunSqlDataRow(sQL);
            if (row == null)
            {
                return null;
            }
            fit.userid = (int) row["userid"];
            fit.webdomain = row["webdomain"].ToString();
            fit.noscroll = (int) row["noscroll"];
            fit.RateCode = row["RateCode"].ToString();
            fit.css = row["css"].ToString();
            fit.sloganResv = row["sloganResv"].ToString();
            fit.sloganMod = row["sloganMod"].ToString();
            fit.sloganCxl = row["sloganCxl"].ToString();
            fit.sloganNewResv = row["sloganNewResv"].ToString();
            fit.EmailFrom = row["EmailFrom"].ToString();
            fit.EmailAlias = row["EmailAlias"].ToString();
            fit.EmailTitle = row["EmailTitle"].ToString();
            fit.languagetype = (int) row["languagetype"];
            fit.IATA = row["IATA"].ToString();
            fit.CardVE = row["CardVE"].ToString();
            fit.MemberType = row["MemberType"].ToString();
            fit.IsMember = (bool) row["IsMember"];
            fit.Corp_ID = (int) row["Corp_id"];
            fit.CardRemark = row["CardRemark"].ToString();
            return fit;
        }
    }
}

